package com.test.enumtest;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 1.体重变化
 */
public enum EnumSGA1 {

    // 在过去二个星期内，您的体重是呈现
    ANSWER2_REDUCE(1, 1, "减少"),
    ANSWER2_INVARIANT(2, 0, "不变"),
    ANSWER2_INCREASE(4, 0, "增加");

    public final int id;
    public final int score;
    public final String name;

    EnumSGA1(int id, int score, String name) {
        this.id = id;
        this.score = score;
        this.name = name;
    }

    /**
     * 获取答案列表 在过去二个星期内，您的体重是呈现
     *
     * @return
     */
    public static List<Map<String, Object>> getAnswerList() {
        List<Map<String, Object>> list = new ArrayList<>();
        list.add(createMap(1));
        list.add(createMap(2));
        list.add(createMap(4));
        return list;
    }

    /**
     * 根据id获取枚举
     *
     * @param id
     * @return
     */
    public static EnumSGA1 get(int id) {
        switch (id) {
            case 1:
                return ANSWER2_REDUCE;
            case 2:
                return ANSWER2_INVARIANT;
            case 4:
                return ANSWER2_INCREASE;
            default:
                return null;
        }
    }

    /**
     * 根据id获取分数
     *
     * @param id
     * @return
     */
    public static int getScore(int id) {
        EnumSGA1 en = EnumSGA1.get(id);
        if (en != null) {
            return en.score;
        } else {
            return -1;
        }
    }

    private static Map<String, Object> createMap(int id) {
        Map<String, Object> map = new HashMap<>();
        map.put("id", EnumSGA1.get(id).id);
        map.put("name", EnumSGA1.get(id).name);
        map.put("score", EnumSGA1.get(id).score);
        return map;
    }
}
